﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharedGenomics.Annotations
{
    [Serializable]
    public class PubMedSearchAnnotation : IAnnotation, IWebSearchable
    {
        public PubMedSearchAnnotation(int entrezGeneId)
        {
            this.EntrezGeneId = entrezGeneId;
        }

        public int EntrezGeneId { get; private set; }

        public AnnotationKey AnnotationKey
        {
            get { return AnnotationKey.PubMedSearch; }
        }

        public string Description
        {
            get { return SummaryText; }
        }

        public string EncodedKey
        {
            get
            {
                return "<annotation type=\"PubMed\"><entrezGeneId>" + System.Security.SecurityElement.Escape(this.EntrezGeneId.ToString()) + "</entrezGeneId><url>" + System.Security.SecurityElement.Escape(SearchUri.ToString()) + "</url></annotation>";
            }
        }

        public Uri SearchUri
        {
            get
            {
                string searchUri = String.Format("http://www.ncbi.nlm.nih.gov/sites/entrez?itool=gene_full_report&DbFrom=gene&Cmd=Link&LinkName=gene_pubmed&IdsFromResult={0}", this.EntrezGeneId);
                return new Uri(searchUri);
            }
        }

        public string SummaryText
        {
            get { return String.Format("PubMed search on {0}", this.EntrezGeneId); }
        }
    }
}
